package com.fly.demo.zip;

import android.Manifest;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.fly.demo.R;

import me.weyye.hipermission.HiPermission;
import me.weyye.hipermission.PermissionCallback;

/*压缩文件*/
public class Main8Activity extends AppCompatActivity {

    private Context mContext = this;

    private final int REQUEST_CODE_WRITE = 1000;

    private final String TAG = Main8Activity.class.getName();

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main8);


        button = findViewById(R.id.main8_btnZip);

        writeExternalStoragePermission();
    }

    //获取写入内存卡的权限
    private void writeExternalStoragePermission() {
        HiPermission.create(mContext).checkSinglePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionCallback() {
            @Override
            public void onClose() {
                Log.d(TAG, "--onClose");
            }

            @Override
            public void onFinish() {
                Log.d(TAG, "--onFinish");
            }

            @Override
            public void onDeny(String permission, int position) {
                Toast.makeText(mContext, "为了您能正常使用此功能，请允许此功能.", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onGuarantee(String permission, int position) {
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String filePath = Environment.getExternalStorageDirectory().getPath() + "/attence/face/";
                        String fileName = "320911199110314638.jpg";
                        String zipPath = Environment.getExternalStorageDirectory().getPath() + "fa.zip";
                   //     ZipOutputStream zip = new ZipOutputStream("fa.zip");
                        try {
                   //         ZipUtils.zipFiles(filePath, fileName, zipPath);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        });
    }
}
